package com.softline.documentsmall.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.softline.documentsmall.dao.RelateBookMapper;
import com.softline.documentsmall.entity.RelateBook;
import com.softline.documentsmall.ret.BusinessErrorEnum;
import com.softline.documentsmall.ret.ReturnVO;
import com.softline.documentsmall.ret.ReturnVOUtils;
import com.softline.documentsmall.service.RelateBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author wph
 * @Date 2021/2/3 14:18
 */
@Service
@Slf4j
public class RelateBookServiceImpl extends ServiceImpl<RelateBookMapper, RelateBook> implements RelateBookService {

    @Autowired
    RelateBookMapper relateBookMapper;

    @Override
    public ReturnVO insert(RelateBook relateBook) {
        try {
            relateBookMapper.insert(relateBook);
        } catch (Exception e) {
            return ReturnVOUtils.businessFail(BusinessErrorEnum.FAIL);
        }
        return ReturnVOUtils.success();
    }

    @Override
    public ReturnVO updateRelateBookById(RelateBook relateBook) {
        try {
            //有的更新 没有不需要
            relateBookMapper.updateByPrimaryKeySelective(relateBook);
        } catch (Exception e) {
            return ReturnVOUtils.businessFail(BusinessErrorEnum.FAIL);
        }
        return ReturnVOUtils.success();
    }

    @Override
    public List<RelateBook> selectList( String title, Integer dicId, Integer pageNo, Integer pageSize) {
        return relateBookMapper.selectListLocal( title, dicId, (pageNo - 1) * pageSize, pageSize);
    }

    @Override
    public long selectCountLoacl(String title,Integer dicId) {
        return relateBookMapper.selectLocalCount(title, dicId);
    }

    @Override
    public RelateBook selectById(int id) {
        return relateBookMapper.selectById(id);
    }

}
